<div class="layui-card-body ">
    <form id="update" style="margin-top: 15px;" class="layui-form" action="{{route('admin.member.update')}}">
        @csrf
        <div class="layui-form-item">
            <label class="layui-form-label">头像</label>
            <div class="layui-input-block">
                <div class="layui-upload">
                    <button type="button" class="layui-btn" id="thumb">上传图片</button>
                    <div class="layui-upload-list">
                        <img class="layui-upload-img" src="/{{$data['medium_avatar']}}" id="pic" width="100" height="100">
                        <p id="demoText"></p>
                        <input type="hidden" name="medium_avatar" value="{{$data['medium_avatar']}}">
                    </div>
                    <div style="width: 95px;">
                        <div class="layui-progress layui-progress-big" lay-showpercent="yes" lay-filter="progress">
                            <div class="layui-progress-bar" lay-percent=""></div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">所属机构</label>
            <div class="layui-input-block">
                <input type="hidden" name="org_code" id="org_code" value="{{$data['org_code']}}" />
                <div id="org_id"></div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">岗位</label>
            <div class="layui-input-block">
                <select name="post_id">
                    <option value="">请选择岗位</option>
                    @foreach($post as $vo)
                        <option value="{{$vo['id']}}" @if($vo['id'] == $data['post_id'])selected="selected"@endif>{{$vo['name']}}</option>
                    @endforeach
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">用户名</label>
            <div class="layui-input-block">
                <input type="hidden" name="id" value="{{$data['id']}}">
                <input type="text" name="name" autocomplete="off" value="{{$data['username']}}"  placeholder="请输入用户名"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">昵称</label>
            <div class="layui-input-block">
                <input type="text" name="nickname" autocomplete="off" value="{{$data['nickname']}}"  placeholder="请输入用户名"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">邮箱</label>
            <div class="layui-input-block">
                <input type="text" name="email" autocomplete="off" value="{{$data['email']}}"  placeholder="请输入邮箱"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">手机号</label>
            <div class="layui-input-block">
                <input type="text" name="mobile" autocomplete="off" value="{{$data['mobile']}}"  placeholder="请输入手机号"
                       class="layui-input">
            </div>
        </div>
    </form>
</div>
<script src="{{asset('layui/modules/xm-select.js')}}"></script>
<script src="{{asset('js/tree/select.js')}}"></script>
<script>
    var idx = -1;
    layui.use(['xmSelect','upload','element','form'], function () {
        var xmSelect = layui.xmSelect,
            element = layui.element,upload = layui.upload;
        let org=selectTreeParams('#org_id','org_id','请选择',"{{$data['org_id']}}", {!! $org !!},function (data){
            $("input[name='org_code']").val(data['arr'][0]['code'])
        });
        xmSelect.render(org)
        var uploadInst = upload.render({
            elem: '#thumb'
            ,url: '{{route('admin.member.create.attach')}}'
            ,field: "img"
            ,before: function(obj){
                obj.preview(function(index, file, result){
                    $('#pic').attr('src', result); //图片链接（base64）
                });
                element.progress('progress', '0%'); //进度条复位
                layer.msg('上传中', {icon: 16, time: 0});
            }
            ,data: {"_token": "{{csrf_token()}}","path": "member"}
            ,done: function(res){
                if(res.code > 0){
                    return layer.msg('上传失败');
                }
                $('#demoText').html('');//置空上传失败的状态
                $('input[name="medium_avatar"]').val(res.path);
            }
            ,error: function(){
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function(){
                    uploadInst.upload();
                });
            }
            //进度条
            ,progress: function(n, elem, e){
                element.progress('progress', n + '%');
                if(n == 100){
                    layer.msg('上传完毕', {icon: 1});
                }
            }
        });
    });
</script>

